package com.issac.controller;

import com.issac.common.R;
import com.issac.entity.Contract;
import com.issac.service.ContractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 购销合同
 */
@RestController
@RequestMapping("/contract")
public class ContractController {
    @Autowired ContractService contractService;

    /**
     * 新增购销合同
     * @param contract 合同
     */
    @PostMapping("/createContract")
    public R createContract(@RequestBody Contract contract){
        return contractService.createContract(contract);
    }

    /**
     * 修改购销合同
     * @param contract
     * @return
     */
    @PostMapping("/updateContract")
    public R updateContract(@RequestBody Contract contract){
        return contractService.updateContract(contract);
    }

    /**
     * 删除合同，同时需要删除中间表
     * @param contractId
     * @return
     */
    @PostMapping("/deleteContract/{contractId}")
    public R addFruitToContract(@PathVariable String contractId){
        return contractService.deleteContract(contractId);
    }

    /**
     * 查询所有合同
     * @return ContractVo
     */
    @GetMapping("/queryAllContract")
    public R queryAllContract(){
        return contractService.queryAllContract();
    }

    /**
     * 查询单个合同
     * @param id
     * @return
     */
    @GetMapping("/queryContract/{id}")
    public R queryContract(@PathVariable String id){
        return contractService.queryContract(id);
    }
}
